import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
  const provider = new WebpageViewProvider(context.extensionUri);
  context.subscriptions.push(
    vscode.window.registerWebviewViewProvider(
      WebpageViewProvider.viewType,
      provider
    )
  );
}

class WebpageViewProvider implements vscode.WebviewViewProvider {
  public static readonly viewType = 'progressPoolView';
  constructor(private readonly _extensionUri: vscode.Uri) {}

  resolveWebviewView(
    webviewView: vscode.WebviewView,
    _context: vscode.WebviewViewResolveContext,
    _token: vscode.CancellationToken
  ) {
    webviewView.webview.options = {
      enableScripts: true,
      localResourceRoots: [this._extensionUri],
    };
    webviewView.webview.html = this._getHtmlForWebview();
  }
  private _getHtmlForWebview(): string {
    return `
      <!DOCTYPE html>
      <html style="height:100%;width:100%;padding:0;margin:0;">
        <head>
          <meta charset="UTF-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <title>External Page</title>
        </head>
        <body style="height:100%;width:100%;padding:0;margin:0;font-size:14px;">
          <iframe
            src="http://progress123.online/#/home"
            style="border:none;width:100%;height:100%"
          ></iframe>
        </body>
      </html>
    `;
  }
}
